#include <string>

using namespace std;

class Solution
{
public:
    string compressString(string S)
    {
        string a;
        char b = S[0];
        int num = 0;
        for (auto ch : S)
        {
            if (ch == b)
            {
                num++;
            }
            else
            {
                a += b;
                a += to_string(num);
                b = ch;
                num = 1;
            }
        }
        a += b;
        a += to_string(num);
        return S.size() > a.size() ? a : S;
    }
};